<?php

class Generation {
	
	protected $individuals = array();
	
	public  function addIndividual(Graph $graph) {
		$this->individuals[] = $graph;
	}
	
	public function getIndividuals() {
		return $this->individuals;
	}
	
	public function getIndividualsCount() {
		return count($this->individuals);
	}
	
	public function getBestIndividual() {
		$best = NULL;
		foreach ($this->individuals as $individual) {
			if ($best !== null) {
				if ($best->getFitness() < $individual->getFitness())
				{
					$best = $individual;
				}
			} else {
				$best = $individual;
			}
		}
		return $best;
	}
	
	public function orderIndividuals() {
		
	}
	
	public function printGeneration() {
		$i = 1;
		foreach ($this->getIndividuals() as $individual) {
			echo 'graf ' . $i . ':<br />';
			foreach ($individual->getVertices() as $vertice) {
				echo $vertice->getColor() . '<br />';
			}
			$i++;
		}
	}
}

?>